package cn.neusoft.controller;

import cn.neusoft.pojo.User;
import cn.neusoft.query.UserQuery;
import cn.neusoft.service.IUserService;
import cn.neusoft.vo.ResultBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/user")
public class UserController {

    @Autowired
    IUserService userService;

    @PostMapping      //  请求方式 + 请求路径   post  /user
    public ResultBean add(@RequestBody User user){
        System.out.println("----UserController-----add--------");
        System.out.println(user);
        return userService.add(user);
    }

    @PutMapping    //   put   /user
    public ResultBean update(@RequestBody User user){
        System.out.println("-------UserController--------update-------------");
        System.out.println(user);
        return userService.update(user);
    }

    //  delete   /user/1003
    @DeleteMapping("/{id}")   // http://localhost:8080/user/1003
    public ResultBean del(@PathVariable("id") Integer id){
        System.out.println("-------UserController--------del-------------");
        System.out.println(id);
        return userService.delete(id);
    }

    //  get   /user/1004
    @GetMapping("/{id}")   // http://localhost:8080/user/1003
    public ResultBean getById(@PathVariable("id") Integer id){
        System.out.println("-------UserController--------getById-------------");
        System.out.println(id);
        return userService.getById(id);
    }

    @GetMapping("/all")    //  get  /user/all
    public ResultBean getAll(){
        System.out.println("-------UserController-----getAll--------");
        return userService.getAll();
    }

    @PostMapping("/page")   // post  /user/page
    public ResultBean getByPage(@RequestBody UserQuery userQuery){
        System.out.println("-------UserController--------getByPage-------------");
        System.out.println(userQuery);
        return userService.getByPage(userQuery);
    }

}
